home *** CD-ROM | disk | FTP | other *** search
/ PC-X 1997 October / pcx14_9710.iso / swag / math.swg / 0120_Calculate a quadratic equation.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1997-03-04  |  2.5 KB  |  120 lines

  1. {
  2.   Calculate and make the graphic of an quadratic equation type ax² + bx + c
  3.  
  4.  
  5. Written By:
  6.   Rodrigo Moreira Silveira - ZεU$ - BRASIL
  7.  
  8. You can Find me at:
  9.   InterNet :
  10.     arlindo@solar.com.br
  11.  
  12.   Adress :
  13.     SQS 113 Bl "G" Apto 102
  14.     Brasília - DF - BRASIL
  15.     Cep : 70.376-070
  16.  
  17. }
  18. Program Equation;
  19.  
  20. uses crt,graph;
  21.  
  22. var
  23.   x1,x2,a,b,c : Real;
  24.   grDriver,grMode: integer;
  25.  
  26. Procedure Drawon(xt,yt:real);
  27. Begin
  28.   PutPixel(trunc(320-(10*xt)),trunc(240-(10*yt)),Yellow);
  29. end;
  30.  
  31.  
  32. Procedure grafico;
  33. var x0,y0,x,y : real;
  34. begin
  35.   x := -100; { Calculates x from -100 to 100 (*) }
  36.   drawon(c,0);
  37.   repeat
  38.     x := x + 0.01; { Precision }
  39.     y := (a*(x*x)) + (b*x) + (c);
  40.     drawon(x,y);
  41.   until x >= 100 { Calculates "x" from -100 to 100 (*) }
  42. end;
  43.  
  44. Procedure Calc;
  45. var Delta : Real; Tmp : String[10];
  46. Begin
  47.   SetColor(White);
  48.   if a <> 0 then
  49.   begin
  50.     Delta := (b*b) - (4*a*c);
  51.     if Delta >= 0 then
  52.     begin
  53.       OutTextXY(0,0,'Delta () =');
  54.       Tmp:= '';
  55.       str(delta:1:6,Tmp);
  56.       OutTextXY(100,0,tmp);
  57.       X1 := (-b) + Sqrt(Delta);
  58.       X2 := (-b) - Sqrt(Delta);
  59.       Tmp:= '';
  60.       str(x1:1:6,Tmp);
  61.       OutTextXY(0,10,'x'' =');
  62.       OutTextXY(35,10,tmp);
  63.       Tmp:= '';
  64.       str(x2:1:6,Tmp);
  65.       OutTextXY(0,20,'x'''' =');
  66.       OutTextXY(40,20,tmp);
  67.     end
  68.     else OutTextXY(0,0,'Delta () < 0');
  69.     end
  70.   else
  71.   begin
  72.     if b <> 0 then begin
  73.       X1 := (c / b);
  74.       str(x1:1:6,Tmp);
  75.       OutTextXY(0,0,'x =');
  76.       OutTextXY(25,0,tmp); end
  77.     else OutTextXY(0,0,'Constant Function');
  78.   end;
  79. end;
  80.  
  81. Procedure DrawCartesian;
  82. var i,y : Word;
  83. Begin
  84.   SetColor(LightGray);
  85.   for i := 1 to 96 do
  86.     Line(0,i*10,640,i*10);
  87.   for i := 1 to 129 do
  88.     Line(i*10,0,i*10,480);
  89.   SetColor(White);
  90.   Line(0,240,640,240);
  91.   Line(320,0,320,480);
  92.   OutTextXY(0,230,'x');
  93.   OutTextXY(310,0,'y');
  94.   OutTextXY(310,230,'o');
  95. end;
  96.  
  97. begin
  98.   TEXTMODE(co80);
  99.   Writeln('This Prorgam will calculate and make a graphic of an equation ax² + bx + c');
  100.   WriteLn;WriteLn;
  101.   Write('Type a Real equivalence to "a" : ');
  102.   readln(a);
  103.   Write('Type a Real equivalence to "b" : ');
  104.   readln(b);
  105.   Write('Type a Real equivalence to "c" : ');
  106.   readln(c);
  107.   grDriver := 9; {VGA}
  108.   grMode := 2; {VGAHi = 650x480}
  109.   initgraph(grDriver,grMode,'..\');
  110.   DrawCartesian;{Draw The Cartesian}
  111.   Calc;{Calculates  and the roots}
  112.   grafico;{Calculates x and make the graphic}
  113.   repeat until keypressed;
  114.   readkey;
  115.   textmode(co80);{Returns to TextMode}
  116. end.
  117.  
  118.  
  119.  
  120.